//
//  DeviceCtrlVC_light.m
//  DoubleJinGe
//
//  Created by Rex on 16/5/25.
//  Copyright © 2016年 Rex. All rights reserved.
//

#import "DeviceCtrlVC_light.h"
#import "MTTCircularSlider.h"
#import "LYImageColorPicker.h"
#import "UIView+ColorOfPoint.h"
#import "CustomImageview.h"

//#import "LightTimeListController.h"

@interface DeviceCtrlVC_light ()
//<ASValueTrackingSliderDataSource>
{
    CALayer *_colorLayer;
    CGFloat _hue, _saturation, _luminosity, _alpha;
}
@property (weak, nonatomic) IBOutlet UIImageView *hueCrosshair;
@property (weak, nonatomic) IBOutlet UIView *baseBgView;
//@property (weak, nonatomic) IBOutlet ASValueTrackingSlider *lightSlider;
@property (weak, nonatomic) IBOutlet CustomImageview *lightColorBgView;

@property (weak, nonatomic) IBOutlet UIButton *SwitchBtn;

@end

@implementation DeviceCtrlVC_light


-(UIStatusBarStyle)preferredStatusBarStyle

{
    
    return UIStatusBarStyleDefault;  //默认的值是黑色的
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
//    self.lightSlider.dataSource=self;
    [self setNavigationBarTitle:@"彩灯控制"];
    self.lightColorBgView.userInteractionEnabled = YES;
    self.lightColorBgView.pickedColorDelegate = self;
    
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateInfo:) name:DEVICESTATE object:nil];
//    
//    self.info = self.info;
    
    [self DeviceState];
}

- (void)DeviceState{
    
//    if (self.info.deviceState == 1) {
//        
//        self.SwitchBtn.selected = YES;
//        
//    }else{
//        
//        self.SwitchBtn.selected = NO;
//    }
    
}




- (void)pickedColor:(UIColor *)color and:(NSString *)total andpoint:(CGPoint)center andEnd:(BOOL)end andPercent:(float)percent
{

    
    
    COLOR_HSV hsv= [RGBTransHSV colorToHsv:color];
    //          是指将p相对aView的坐标转换为相对anotherView的坐标
    
    Byte hue =  hsv.H * 255;
    Byte sat =  hsv.S *255;
//    [[JNI_iOS_SDK defaultJNI_iOS_SDK]setDeviceHueSatByUid:_info.uId hue:hue sat:sat];
    CGFloat r = self.lightColorBgView.frame.size.width/2 - 25;

    CGFloat x1   =   self.lightColorBgView.center.x +    r  *   cos(2 * (percent - 0.25 ) *   M_PI   );
    CGFloat y1   =   self.lightColorBgView.center.y   +   r   *   sin(2 * (percent - 0.25)   *   M_PI   );
    
    
    self.hueCrosshair.center=CGPointMake(x1, y1);
    
}



-(void)updateInfo:(NSNotification*)notic
{

    
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self setLightSliderAttributes];
   
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //self.colorPickerSlider.frame=self.lightColorBgView.frame;
}
- (void)setLightSliderAttributes {
    
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setNumberStyle:NSNumberFormatterPercentStyle];
//    [self.lightSlider setNumberFormatter:formatter];   // 百分比样式
//    
//    self.lightSlider.font = [UIFont fontWithName:@"Menlo-Regular" size:23];
//    self.lightSlider.popUpViewAnimatedColors = @[[UIColor purpleColor], [UIColor orangeColor], [UIColor yellowColor]];
//    self.lightSlider.popUpViewArrowLength = 10.0;
    
}

//- (IBAction)lightSliderAction:(ASValueTrackingSlider *)sender {
//    
//
//}
//
//-(NSString *)slider:(ASValueTrackingSlider *)slider stringForValue:(float)value
//{
//    [[JNI_iOS_SDK defaultJNI_iOS_SDK]setDeviceLevelByDeviceUID:_info.uId value:(value*255.f)];
//    return [NSString stringWithFormat:@"%.f%%",value*100];
//}
//
//- (void)sliderEditingDidEnd:(MTTCircularSlider*)slider {
//    
//
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 开关灯
- (IBAction)OpenPowerAction:(UIButton *)sender {
   
//    if (self.info.deviceState == 1) {
//        
//        self.SwitchBtn.selected = NO;
//        
//    }else{
//        
//        self.SwitchBtn.selected = YES;
//        
//    }
//      [[JNI_iOS_SDK defaultJNI_iOS_SDK] setDeviceStateByShortAddr:self.info.shortAdr endPoint:self.info.endPoint state:!self.info.deviceState];
    
    
}

#pragma mark - 定时
- (IBAction)pushVC:(id)sender {
    
//    LightTimeListController *vc = [[LightTimeListController alloc] initWithNibName:@"LightTimeListController" bundle:nil];
//    
//    vc.info = self.info;
    
    
//    [self.navigationController pushViewController:vc animated:YES];
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
